package com.example.md.mddemo.services;

import com.example.md.mddemo.entity.Customer;
import com.example.md.mddemo.entity.value_obj.CustContactPerson;
import com.example.md.mddemo.repo.CustomerRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Copyright © 2018年 ziniuxiaozhu. All rights reserved.
 *
 * @Author 临江仙 hzqiuxm@163.com
 * TODO:亲爱的临江仙，请写点注释吧...........
 * @Date 2018/8/9 18:40
 */
@Service
public class CustomerService {

    private static final Logger log = LoggerFactory.getLogger(CustomerService.class);

    @Autowired
    private CustomerRepository customerRepository;

    /**
     *
     * @param custcode
     * @return 只返回需要的信息CustContactPerson，如果不转化的话，其他没有值的字段也会返回，只不过是空值
     */

    public List<List<CustContactPerson>> findContactInfoByCustcode(String custcode){

        List<Customer> byCustCode = customerRepository.findCustomersByCustCode(custcode);

        List<List<CustContactPerson>> custContactPeople = new ArrayList<>();
        for (int i = 0; i < byCustCode.size(); i++) {
            Customer customer = new Customer();
            customer = byCustCode.get(i);
            custContactPeople.add(customer.getContactList());
        }

        return custContactPeople;

    }

    /**
     * 根据客户编号查询客户名称
     * @param custcode
     * @return 客户名称列表
     */
    public List<String> findCustomerByCustCode(String custcode){

        List<String> byCustCode = customerRepository.findCustomerByCustCode(custcode);

        return byCustCode;

    }

}
